'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:PersonnelWcbsCtrl
 * @description
 * # PersonnelWcbsCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('PersonnelWcbsCtrl', function($scope, openApi, Util, $routeParams, FormSubmit,localStorageService,$location) {
        var id = $scope.process_id = $routeParams.id
        $scope.submit = function(operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.goOut;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options,$scope);
        };
        $scope.chooseposition = function() {
            Util.savaParamForReview($scope.param, id);
            $location.path("sign/chooselocation");
          };
        $scope.validate = function() {
            if (!$scope.param.startOutTime) {
                Util.Toast("请选择外出起始日期");
                return;
            }
            if (!$scope.param.endOutTime) {
                Util.Toast("请选择外出结束日期");
                return;
            }
            if (!Util.checkDays($scope.param.costTime)) {
                Util.Toast("外出时长要为0.5的倍数");
                return;
            }
            if (!$scope.param.outPosition) {
                Util.Toast("请填写外出地点");
                return;
            }

            if (!$scope.param.outReason) {
                Util.Toast("请填写外出事由");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                var location = localStorageService.get("signparam");
                localStorageService.remove("signparam");
                if (location && location.point) {
                    $scope.param = Object.assign({}, $scope.param, { address: location.address }, { lat: location.point.latitude }, { lng: location.point.longitude });
                }
            });
        };
        // 初始化
        init();
    });